#include <glib.h>

static void _queue_foreach_print_func(gpointer data, gpointer       user_data)
{
    GList *l = NULL;

    l = (GList *)data;
    if(NULL == l) {
        g_print("input param error! \n");
        return;
    }

    g_print("user_data:%s, data:%s \n", (gchar *)user_data, (gchar *)l->data);
}

static void _queue_free_func(gpointer data)
{
    GList *l;

    l = (GList *)data;
    if(NULL == l) {
        g_print("input param error! \n");
        return;
    }

    g_free((gchar *)l->data);
    g_list_free(l);
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;
    GList *list[3] = {NULL, NULL, NULL};

    q = g_queue_new();

    list[0] = g_new0(GList, 1);
    list[0]->data = (gpointer)g_strdup("hello");
    list[1] = g_new0(GList, 1);
    list[1]->data = (gpointer)g_strdup("foo");
    list[2] = g_new0(GList, 1);
    list[2]->data = (gpointer)g_strdup("bar");

    g_queue_push_tail(q, (gpointer)list[0]);
    g_queue_push_tail(q, (gpointer)list[1]);
    g_queue_push_tail(q, (gpointer)list[2]);

    g_queue_foreach(q, _queue_foreach_print_func, "Queue");

    g_queue_free_full(q, _queue_free_func);

    return 0;
}